﻿using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.Models;
using MiniFox.Platform.OAuth2.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Platform.OAuth2.Providers
{
    /// <summary>
    /// 通行证数据提供者
    /// </summary>
    [AutoRegister]
    public interface IPassportProvider
    {
        #region 检查可用性

        /// <summary>
        /// 检查登录名是否未使用
        /// </summary>
        /// <param name="loginName">要检查的登录名</param>
        /// <returns></returns>
        bool IsUnusedLoginName(string loginName);
        /// <summary>
        /// 检查注册邮箱是否未使用
        /// </summary>
        /// <param name="secEmail">要检查的注册邮箱</param>
        /// <returns></returns>
        bool IsUnusedSecEmail(string secEmail);
        /// <summary>
        /// 检查注册手机号是否未使用
        /// </summary>
        /// <param name="cellphone">要检查的手机号</param>
        /// <returns></returns>
        bool IsUnusedCellphone(string cellphone);

        #endregion

        #region 注册相关

        /// <summary>
        /// 创建身份信息
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="secEmail"></param>
        /// <param name="cellphone"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        OpenAuthIdentity CreateIdentity(string loginName, string secEmail, string cellphone, string password);
        /// <summary>
        /// 创建身份信息
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        OpenAuthIdentity CreateIdentityWithLoginName(string loginName, string password);
        /// <summary>
        /// 创建身份信息
        /// </summary>
        /// <param name="secEmail"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        OpenAuthIdentity CreateIdentityWithSecEmail(string secEmail, string password);
        /// <summary>
        /// 创建身份信息
        /// </summary>
        /// <param name="cellphone"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        OpenAuthIdentity CreateIdentityWithCellphone(string cellphone, string password);
        /// <summary>
        /// 激活身份信息
        /// </summary>
        /// <param name="openAuthIdentity"></param>
        void ActivateIdentity(OpenAuthIdentity openAuthIdentity);

        #endregion

        #region 身份提取

        /// <summary>
        /// 通过账户密码获得身份信息
        /// </summary>
        /// <param name="signName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        OpenAuthIdentity GetIdentity(string signName, string password);
        /// <summary>
        /// 通过用户名获得身份信息
        /// </summary>
        /// <param name="signName"></param>
        /// <returns></returns>
        OpenAuthIdentity GetIdentity(string signName);
        /// <summary>
        /// 通过注册邮箱获得身份信息
        /// </summary>
        /// <param name="secEmail"></param>
        /// <returns></returns>
        OpenAuthIdentity GetIdentityByEmail(string secEmail);
        /// <summary>
        /// 通过手机号获得身份信息
        /// </summary>
        /// <param name="cellphone"></param>
        /// <returns></returns>
        OpenAuthIdentity GetIdentityByCellphone(string cellphone);
        /// <summary>
        /// 通过指定passport token获得本系统身份信息
        /// </summary>
        /// <param name="passportToken"></param>
        /// <returns></returns>
        OpenAuthIdentity GetIdentity(PassportToken passportToken);
        /// <summary>
        /// 通过指定第三方open user信息获得本系统身份信息
        /// </summary>
        /// <param name="openAuthUser"></param>
        /// <returns></returns>
        OpenAuthIdentity GetIdentity(ExternalOpenAuthUser openAuthUser);

        #endregion

        #region 操作 passport token

        /// <summary>
        /// 为指定身份保存passport令牌用于验证
        /// </summary>
        /// <param name="passportToken">passport令牌</param>
        /// <param name="identity">身份信息</param>
        /// <param name="clientInfomation">客户端信息</param>
        /// <returns></returns>
        void SavePassportToken(OpenAuthIdentity identity, PassportToken passportToken, ClientInfomation clientInfomation);
        /// <summary>
        /// 禁用现有token
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="clientInfomation"></param>
        void DisablePassportToken(OpenAuthIdentity identity, ClientInfomation clientInfomation);

        #endregion

        /// <summary>
        /// 保存第三方open user信息，缺少时创建，已存在则更新，注：实现时，需要根据本接口调用频率定义缓存策略，以避免频率更新数据库
        /// </summary>
        /// <param name="openAuthUser"></param>
        void SaveOpenAuthUser(ExternalOpenAuthUser openAuthUser);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <returns></returns>
        AuthorizeResult GetDeviceAuthorize(Ticket authTicket);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="cellphone"></param>
        /// <param name="pinCode"></param>
        /// <returns></returns>
        bool PinCodeValidation(Ticket authTicket, string cellphone, string pinCode);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ticket"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        bool ResetPassword(Ticket ticket, string password);
        /// <summary>
        /// 扫码后，以第三方用户信息设置票据，用户信息不存在时需自动创建
        /// </summary>
        /// <param name="authTicket"></param>
        /// <param name="openAuthUser"></param>
        /// <returns></returns>
        bool SetOpenAuthUser(Ticket authTicket, ExternalOpenAuthUser openAuthUser);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="authTicket"></param>
        void SetDeviceAuthorized(Ticket authTicket);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="openAuthUser"></param>
        /// <param name="identity"></param>
        void BindIdentity(ExternalOpenAuthUser openAuthUser, OpenAuthIdentity identity);
    }
}
